/**
 * Univer 相关类型定义
 */

export interface UniverAPI {
  createWorkbook: (config: WorkbookConfig) => void
  getActiveWorkbook: () => Workbook | null
  getWorkbook: (id: string) => Workbook | null
  dispose: () => void
  // XLSX 导入导出功能
  importXLSXToSnapshotAsync: (file: File) => Promise<IWorkbookData>
  exportXLSXByUnitIdAsync: (unitId: string) => Promise<File>
}

export interface Workbook {
  id: string
  name: string
  getId: () => string
  getActiveSheet: () => Worksheet | null
  getSheet: (id: string) => Worksheet | null
  createSheet: (config: SheetConfig) => void
  deleteSheet: (id: string) => void
}

export interface Worksheet {
  id: string
  name: string
  getCellData: () => Record<string, Record<string, CellData>>
  getRange: () => Range
  setCellValue: (row: number, column: number, value: any) => void
  setCellFormula: (row: number, column: number, formula: string) => void
  clear: () => void
}

export interface CellData {
  v?: any // value
  f?: string // formula
  s?: any // style
}

export interface Range {
  startRow: number
  startColumn: number
  endRow: number
  endColumn: number
}

export interface WorkbookConfig {
  id: string
  name: string
  sheetOrder: string[]
  locale: string
  styles: Record<string, any>
  sheets: Record<string, SheetConfig>
}

export interface SheetConfig {
  id: string
  name: string
  cellData: Record<string, Record<string, CellData>>
  rowCount: number
  columnCount: number
  rowHeader: {
    width: number
    hidden: boolean
  }
  columnHeader: {
    height: number
    hidden: boolean
  }
  selections: string[]
  rightToLeft: boolean
}

// IWorkbookData 类型定义（用于 XLSX 导入导出）
export interface IWorkbookData {
  id: string
  name: string
  sheetOrder: string[]
  locale: string
  styles: Record<string, any>
  sheets: Record<string, ISheetData>
}

export interface ISheetData {
  id: string
  name: string
  cellData: Record<string, Record<string, CellData>>
  rowCount: number
  columnCount: number
  rowHeader: {
    width: number
    hidden: boolean
  }
  columnHeader: {
    height: number
    hidden: boolean
  }
  selections: string[]
  rightToLeft: boolean
}
